package com.example.java250919_spring_principle.controller;

import com.example.java250919_spring_principle.config.BeanConfig;
import com.example.java250919_spring_principle.model.Dog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/scope")
public class ScopeController {
    @Autowired
    private ApplicationContext context;
    @Autowired
    private BeanConfig beanConfig;

    @Autowired
    private Dog singleDog;

    @Autowired
    private Dog prototypeDog;

    @Autowired
    private Dog requestDog;

    @Autowired
    private Dog sessionDog;

    @Autowired
    private Dog applicationDog;

    @RequestMapping("/test")
    public String test(){
        BeanConfig bean = context.getBean(BeanConfig.class);
        return "context bean:" + bean + ",autowired:" + beanConfig;
    }

    @RequestMapping("/single")
    public String single(){
         Dog contextDog = (Dog) context.getBean("singleDog");
        return "context bean:" + contextDog + ",<br/> autowired:" + singleDog;
    }

    @RequestMapping("/prototype")
    public String prototype(){
        Dog contextDog = (Dog) context.getBean("prototypeDog");
        return "context bean:" + contextDog + ",<br/>autowired:" + prototypeDog;
    }


    @RequestMapping("/request")
    public String requestDog(){
        Dog contextDog = (Dog) context.getBean("requestDog");
        return "context bean:" + contextDog + ",<br/>autowired:" + requestDog;
    }

    @RequestMapping("/session")
    public String sessionDog(){
        Dog contextDog = (Dog) context.getBean("sessionDog");
        return "context bean:" + contextDog + ",<br/>autowired:" + sessionDog;
    }

    @RequestMapping("/application")
    public String applicationDog(){
        Dog contextDog = (Dog) context.getBean("applicationDog");
        return "context bean:" + contextDog + ",<br/>autowired:" + applicationDog;
    }
}













































